package epsi.mobile.views;

import epsi.mobile.constants.ConfigurationConstants;
import epsi.mobile.helpers.GPSTracker;
import epsi.mobile.helpers.JsonStoreUpdateHelper;
import epsi.mobile.storelocator.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{

	private ImageButton launchStoreList;
	private Button launchProximityMap;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent gps = new Intent(MainActivity.this,GPSTracker.class);
		startService(gps);
		
		//Creation or update of the store list
		new JsonStoreUpdateHelper(MainActivity.this).execute();
		
		//Main View Creation , Launch the main activity
		setContentView(R.layout.activity_main);
		
		
		launchStoreList = (ImageButton) findViewById (R.id.bt_locate);
		launchStoreList.setOnClickListener(this);
		
		
		
		launchProximityMap = (Button) findViewById (R.id.edt_map_proximity);
		launchProximityMap.setOnClickListener(this);
		
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
	super.onSaveInstanceState(outState);    
	}

	@Override
	protected void onRestoreInstanceState(Bundle state) {
	super.onRestoreInstanceState(state);    
	}
	

	@Override
	public void onClick(View v) 
	{
		
	    if(v == launchStoreList)
		{
	        TextView text = (TextView) findViewById(R.id.edt_locate);
			Intent listIntent = new Intent(MainActivity.this, StoreListActivity.class);
			listIntent.putExtra("listRequest",text.getText().toString());
			startActivity(listIntent);
		}
	    
	    else if(v == launchProximityMap)
	    {
	    	Intent mapIntent = new Intent(MainActivity.this, StoreListActivity.class);
	    	mapIntent.putExtra("listRequest",ConfigurationConstants.MapProximityRequest);
	    	startActivity(mapIntent);
	    }
	}

}
